//
//  AdressData.swift
//  LoveFreshBeen
//
//  Created by Gao on 17/2/9.
//  Copyright © 2017年 Odm. All rights reserved.
//


//{
//    "code": 200,
//    "msg": "查询成功",
//    "reqid": "ee2fa99ef9866f928b33b19dc417256c",
//    "data": [
//    {
//    "id": "4351645",
//    "accept_name": "维尼的小熊",
//    "telphone": "18833331111",
//    "province_id": "1",
//    "province_name": "北京",
//    "city_id": "2",
//    "city_name": "北京市",
//    "district_id": "0",
//    "district_name": "",
//    "address": "人民大会堂 9527办公室",
//    "lng": "116.43704865748",
//    "lat": "39.927583644703",
//    "lng_map": "116.43704865748",
//    "lat_map": "39.927583644703",
//    "isnew": "1",
//    "version": "2",
//    "addr_for_dealer": "西水井胡同1号",
//    "gender": "1"
//    }
//    ]
//}

import UIKit

class Adress: NSObject {
    
    var accept_name: String?
    var telphone: String?
    var province_name: String?
    var city_name: String?
    var address: String?
    var lng: String?
    var lat: String?
    var gender: String?
}

class AdressData: NSObject {
    var code: Int = -1
    var msg: String?
    var data: [Adress]?
    
    // 返回容器类中的所需要存放的数据类型 (以 Class 或 Class Name 的形式)。
    class func modelContainerPropertyGenericClass() -> [AnyHashable: Any] {
        return ["data": Adress.self]
    }
    
    class func loadMyAdressData(_ completion:(_ data: AdressData?, _ error: NSError?) -> Void) {
        guard let path = Bundle.main.path(forResource: "MyAdress", ofType: nil) else{
            return
        }
        
        let url = URL(fileURLWithPath: path)
        
        guard let jsonString = try? String(contentsOf: url) else{
            return
        }
        
        let adressData = AdressData.yy_model(withJSON: jsonString)
        
        if adressData != nil {
            completion(adressData, nil)
        }
    }
}
